#include "watchDog.hpp"

static std::string WDT_DEVICE_NAME = "wdt";

void WatchDog::run(void *parameter)
{
    //* bind watchdog device
    this->wdgDev = rt_device_find(WDT_DEVICE_NAME.c_str());
    //* init watchdog device
    rt_device_init(this->wdgDev);
    //* set watchdog timeout
    rt_uint32_t timeout = 2; /*sec*/
    rt_device_control(this->wdgDev, RT_DEVICE_CTRL_WDT_SET_TIMEOUT, &timeout);
    //* start watchdog
    rt_device_control(this->wdgDev, RT_DEVICE_CTRL_WDT_START, RT_NULL);

    while (1)
    {
        if (this->SemKey_0->wait())
        {
            rt_device_control(this->wdgDev, RT_DEVICE_CTRL_WDT_KEEPALIVE, RT_NULL);
            rt_kprintf("Feed the dog!/r/n");
        }
        rt_thread_mdelay(100);
    }
}
